package com.itheima.app.controller;

import com.itheima.app.manager.MakeFriendManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class MakeFriendController {

    @Autowired
    private MakeFriendManager makeFriendManager;

    // 今日佳人
    @GetMapping("/tanhua/todayBest")
    public ResponseEntity findTodayBest() {
        // 调用manager
        return makeFriendManager.findTodayBest();
    }

    // 推荐用户列表
    @GetMapping("/tanhua/recommendation")
    public ResponseEntity findRecommendUserVoByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        // 调用manager
        return makeFriendManager.findRecommendUserVoByPage(pageNum, pageSize);
    }

    // 推荐用户详情
    @GetMapping("/tanhua/{id}/personalInfo")
    public ResponseEntity findRecommendUserVoDetail(@PathVariable("id") Long recommendUserId) {
        // 调用manager
        return makeFriendManager.findRecommendUserVoDetail(recommendUserId);
    }

    // 查看陌生人问题
    @GetMapping("/tanhua/strangerQuestions")
    public ResponseEntity findStrangerQuestions(Long userId) {
        // 调用manager
        return makeFriendManager.findStrangerQuestions(userId);
    }

    // 最近访客
    @GetMapping("/movements/visitors")
    public ResponseEntity findVisitors() {
        // 调用manager
        return makeFriendManager.findVisitors();
    }

    // 上传地理位置
    @PostMapping("/baidu/location")
    public void uploadLocation(@RequestBody Map<String, Object> map) {
        double longitude = (double) map.get("longitude");
        double latitude = (double) map.get("latitude");
        String addrStr = String.valueOf(map.get("addrStr"));

        System.out.println(map);

        // 调用manager
        makeFriendManager.uploadLocation(longitude, latitude, addrStr);
    }

    // 搜附近
    @GetMapping("/tanhua/search")
    public ResponseEntity searchNearUserVo(String gender, Integer distance) {
        // 调用manager
        return makeFriendManager.searchNearUserVo(gender, distance);
    }

    // 探花卡片
    @GetMapping("/tanhua/cards")
    public ResponseEntity tanhuaCards() {
        // 调用manager
        return makeFriendManager.tanhuaCards();
    }
}
